package com.hyc.myvideo.data.adapter;


import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.hyc.myvideo.R;
import com.hyc.myvideo.data.adapter.base.BaseListAdapter;
import com.hyc.myvideo.data.api.model.Bounce;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/***
 * 聊天适配器
 */
public class BouncePlayAdapter extends BaseListAdapter<Bounce> {
    public BouncePlayAdapter(Context context, List<Bounce> objects) {
        super(context, objects);
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.activity_adapter_bounce_item, parent, false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        Bounce bounce = mDataList.get(position);
//        //昵称
//        String nickname = String.format(mContext.getString(R.string.huc_my_live_colon),bounce.getName());
//        //消息
//        String wholeStr = nickname+bounce.getNews();
//        StringFormatUtil spanStr = new StringFormatUtil(mContext, wholeStr,nickname, R.color.color_9).fillColor();
        //昵称
        String name = bounce.getName() + "：";
        //消息
        String content = bounce.getNews();
        SpannableString spannableString = new SpannableString(name + content);
        spannableString.setSpan(new ForegroundColorSpan(ContextCompat.getColor(mContext, R.color.color_9)),
                0, name.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

        holder.textWith.setText(spannableString);
        return convertView;
    }

    public static class ViewHolder {
        public ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
        //聊天
        @BindView(R.id.player_t_with)
        TextView textWith;
    }

}
